import { defineStore } from "pinia";
import { LoginQo } from "../../api/user/type";
import { reqLogin } from "../../api/user";

let useUserStore = defineStore("user", ()=>{
    let token:string|null = localStorage.getItem("token")

    const loginAction = async (qo:LoginQo)=>{
        let data = await reqLogin(qo)
        if(data.code === 200){
            token = data.data?.token as string
            localStorage.setItem("token", token)
            return "ok"
        }
        return Promise.reject(data.msg)
    }


    return {
        token,
        loginAction
    }
})

export default useUserStore